package com.bestcem.xm.survey.util;

import com.bestcem.xm.survey.enums.*;

import java.util.*;
import java.util.stream.Collectors;

import static com.bestcem.xm.survey.enums.ExtparamDtypeDataEnum.EXTPARAM_DTYPE_DATA_ENUM;
import static com.bestcem.xm.survey.enums.ExtparamDtypeDataEnum.EXTPARAM_DTYPE_DATA_STRING;
import static com.bestcem.xm.survey.enums.FileInfoFTypeEnum.*;
import static com.bestcem.xm.survey.enums.MemberTypeEnum.*;

/**
 * 常量类
 */
public interface SurveyConstant {

    static String getSurveyProjectJsPathV2(String project_id) {
        return String.format("survey/project/%s/project.js", project_id);
    }

    String LOCAL_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss";

    String OPEN_PREDIX = "\b";

    String RSPD_TIME_FORMAT = "rspd_time_%s";

    String RSPD_STATUS_FORMAT = "rspd_status_%s";

    String RSPD_PROP_FORMAT = "rspd_prop_%s";

    String DLV_CHK_FORMAT = "_dlv_chk_%s";

    String RSPD_FORMAT = "rspd_%s";

    String QORDER_FORMAT = "qorder:%s:%s";

    String SORT_FORMAT = "__SORT_%s";

    String Q_PATH_FORMAT = "q_path_%s";

    String CREATED_FORMAT = "created_%s";

    String DLV_EXT_CHK_FORMAT = "_dlv_ext_chk:%s:%s";

    String DELIVER_DELIVER_ENABLE_RESPONDENT_FORMAT = "deliver:deliver_enable_respondent%s";

    String WXSID_KEY_FORMAT = "User:wx_data:%s";

    String SURVEY_PROJECT_ID_CNT_RESPONDENT_FORMAT = "SURVEY:%s-cnt";

    String SURVEY_CNT_PER_IP_FORMAT_KEY = "Survey:%s:%s:cnt_per_ip";

    String SURVEY_IP_CNT_FORMAT_KEY = "Survey:%s:%s:ip-cnt";

    String USER_TOKEN_VERSION_FORMAT_KEY = "USER:token_version:%s";

    String NAME_LIST_DATA_FORMAT_KEY = "QDES:%s:%s:%s:data";

    String NAME_LIST_TYPE_FORMAT_KEY = "QDES:%s:%s:type";

    String RSPD_SEQ_REDIS_KEY = "__rspd_seq__";

    String RESP_FINISH_COUNT_FORMAT_KEY = "resp_finish_count:%s";

    String SUBMIT_SEQ_FORMAT_KEY = "submit_seq_%s_%s";

    String QUOTE_COUNT_AUTO_INC_LOCK_FORMAT_KEY = "quote_count_auto_inc_lock:%s";

    String TOKEN_HEADER = "Bearer ";

    Integer QDES_PROJECT_STATUS_CREATED = 0;
    Integer QDES_PROJECT_STATUS_RELEASED = 1;
    Integer QDES_PROJECT_STATUS_FINISHED = 2;
    Integer QDES_PROJECT_STATUS_DELETED = 3;

    String WXWORK_MINI_SESSION_PREFIX = "wxwork_mini_session";
    String WX_MINI_SESSION_PREFIX = "wx_mini_session";

    // 外部参数类型
    Integer EXTPARAMTER_DTYPE_STR = 1;  // 字符串
    Integer EXTPARAMTER_DTYPE_INT = 2;  // 整型
    Integer EXTPARAMTER_DTYPE_BOOL = 3;  // BOOL

    List<String> D_TYPE = Arrays.asList("01", "not01", "anothernot01", "readable", "spss_data");

    List<String> D_TYPE_2 = Arrays.asList("readable", "01", "not01", "anothernot01");

    List<String> D_TYPE_3 = Arrays.asList("single", "multiple", "sort");

    List<String> D_TYPE_4 = Arrays.asList("matrix_multiple", "matrix_single", "matrix_blank");

    List<String> D_TYPE_5 = Arrays.asList("proportion", "star_score", "cursor_score");

    List<String> D_TYPE_6 = Arrays.asList("cascader", "geo", "city");

    List<String> D_TYPE_7 = Arrays.asList("evaluation", "score", "matrix_score", "cursor_score", "proportion", "sort");

    Map<String, String> RESPONDENT_EXPORT_MAP = new HashMap<String, String>() {
        {
            put("readable", "可读数据");
            put("01", "01编码");
            put("not01", "非01编码");
            put("anothernot01", "非01编码(左对齐)");
            put("spss_data", "spss");
        }
    };

    Map<String, String> RESPONDENT_EXPORT_MAP2 = new HashMap<String, String>() {
        {
            put("01", "01编码");
            put("not01", "非01编码");
            put("anothernot01", "非01编码(左对齐)");
            put("spss_data", "spss");
        }
    };

    Map<String, String> PROGRESS_BAR_OPERATION_MAP = new HashMap<String, String>() {
        {
            put("0", "survey:rspd.export");
        }
    };

    List<String> COLUMNS_META_FRONT = new ArrayList<String>() {
        {
            add("答卷编号");
            add("答卷状态");
            add("所属投放");
            add("投放渠道");
            add("问卷推送时间");
            add("答题开始时间");
            add("答题结束时间");
            add("答题时长");
            add("所属组织");
            add("组织编号");
        }
    };

    List<String> COLUMNS_META_BEHIND = new ArrayList<String>(29) {
        {
            add("设备类型");
            add("浏览器");
            add("操作系统");
            add("IP");
            add("IP所属国家");
            add("IP所属省份");
            add("IP所属城市");
            add("用户编号");
            add("渠道");
            add("用户名称");
            add("头像");
            add("用户性别");
            add("手机号码");
            add("邮箱");
            add("企业名称");
            add("所在部门");
            add("职位");
            add("用户所在国家");
            add("用户所在省份");
            add("用户所在城市");
            add("AppId（微信）");
            add("问卷编号");
            add("问卷标题");
            add("问卷版本");
            add("投放编号");
            add("答题时长（秒）");
            add("cookie");
            add("答卷类型");
            add("idy_sid");
        }
    };

    List<String> COLUMNS_META = new ArrayList<String>(3) {
        {
            add("渠道");
            add("用户名称");
            add("用户所在国家");
        }
    };

    List<String> COLUMNS_MEMBER = new ArrayList<String>(10) {
        {
            add("联系人ID");
            add("联系人姓名");
            add("联系人手机");
            add("联系人邮箱");
            add("性别");
            add("出生日期");
            add("微信OpenID");
            add("微信AppID");
        }
    };

    List<String> QTYPE1 = new ArrayList<String>(3) {
        {
            //矩阵单选
            add("matrix_single");
            //矩阵填空
            add("matrix_blank");
            //矩阵打分
            add("matrix_score");
        }
    };


    /**
     * 定义字段类型的排序顺序
     */
    List<Integer> COLUMNS_META_SORT = Arrays.stream(ColumnsMetaSortEnum.values()).map(ColumnsMetaSortEnum::getValue).collect(Collectors.toList());

    List<Integer> EXTPARAM_DTYPE_DATA1 = Arrays.asList(EXTPARAM_DTYPE_DATA_STRING.getValue(), EXTPARAM_DTYPE_DATA_ENUM.getValue());

    Map<Integer, String> MEMBER_MTYPE_DICT = new HashMap<Integer, String>() {
        {
            put(MEMBER_MTYPE_INDIVIDUAL.getValue(), MEMBER_MTYPE_INDIVIDUAL.getDesc());
            put(MEMBER_MTYPE_INSTITUTION.getValue(), MEMBER_MTYPE_INSTITUTION.getDesc());
            put(MEMBER_MTYPE_INTERIOR.getValue(), MEMBER_MTYPE_INTERIOR.getDesc());
        }
    };

    Map<Integer, String> RESPONDENT_STATUS_DICT = Arrays.stream(RespondentStatusEnum.values()).collect(Collectors.toMap(RespondentStatusEnum::getValue, RespondentStatusEnum::getDesc));

    Map<Integer, String> RESPONDENT_CLIENT_TYPE_DICT = Arrays.stream(RespondentClientTypeEnum.values()).collect(Collectors.toMap(RespondentClientTypeEnum::getValue, RespondentClientTypeEnum::getName));

    Map<Integer, String> WX_INFO_SEX_DICT = Arrays.stream(WxInfoSexEnum.values()).collect(Collectors.toMap(WxInfoSexEnum::getValue, WxInfoSexEnum::getName));

    List<Integer> RESPONDENT_FORMAL_SOURCE = Arrays.stream(RespondentSourceEnum.values()).map(RespondentSourceEnum::getValue).filter(it -> !Objects.equals(it, RespondentSourceEnum.RESPONDENT_SOURCE_PREVIEW.getValue()) && !Objects.equals(it, RespondentSourceEnum.RESPONDENT_SOURCE_CUSTOM.getValue())).collect(Collectors.toList());


    /**
     * 多选题分题评分规则
     */

    Integer SCORE_RULE_ANY_RIGHT = 0;
    Integer SCORE_RULE_ALL_RIGHT = 1;

    Integer SURVEY_RESPONDENT_EXPORT = 0;

    Integer CONDITION_LIMIT = 5;

    List<String> LEVEL_TITLE = new ArrayList<String>(10) {
        {
            add("省份");
            add("城市");
            add("区县");
            add("街道信息");
        }
    };

    String SURVEY_EXPORT = "survey/export/";

    /**
     * 本地存储路径，upload模块用
     */
    //String LOCAL_STORAGE_PATH = new File(System.getProperty("user.dir")).getParentFile().getPath() + File.separator + "XM" + File.separator + "static";
    //String STATIC_PATH = "/rs/";

    List<String> ATTACHMENT_FILE_NAME = Arrays.asList("base_css", "base_rem_css", "base_js", "base_rem_js");

    List<String> IMG_LIST = Arrays.asList(
            "png",
            "jpeg",
            "jpg",
            "gif",
            "bmp",
            "tif",
            "pcx",
            "tga",
            "exif",
            "fpx",
            "psd",
            "cdr",
            "pcd",
            "dxf",
            "ufo",
            "eps",
            "ai",
            "raw",
            "wmf",
            "webp",
            "avif",
            "apng",
            "heif"
    );

    List<String> VIDEO_TYPE = Arrays.asList(
            "mp4",
            "mov",
            "wmv",
            "avi",
            "flv",
            "webm",
            "3gp",
            "asf",
            "asx",
            "rm",
            "rmvb",
            "m4v",
            "dat",
            "mkv",
            "vob"
    );


    List<String> OTHER_LIST = Arrays.asList(
            "doc",
            "docx",
            "ppt",
            "pptx",
            "txt",
            "sav",
            "caj",
            "rar",
            "zip",
            "gzip",
            "json"
    );

    List<String> AUDIO_TYPE = Arrays.asList("mp3", "wma", "wav", "amr", "m4a", "aac");

    List<String> EXCEL_LIST = Arrays.asList("xls", "xlsx", "csv");

    List<String> PDF_LIST = Collections.singletonList("pdf");

    Map<String, List<String>> TYPE_LIMIT_LIST = new HashMap<String, List<String>>() {
        {
            put("img", IMG_LIST);
            put("audio", AUDIO_TYPE);
            put("video", VIDEO_TYPE);
            put("excel", EXCEL_LIST);
            put("pdf", PDF_LIST);
        }
    };

    List<String> FULL_TYPE_LIST = new ArrayList<String>() {
        {
            addAll(IMG_LIST);
            addAll(VIDEO_TYPE);
            addAll(AUDIO_TYPE);
            addAll(OTHER_LIST);
            addAll(EXCEL_LIST);
            addAll(PDF_LIST);
        }
    };


    Map<Integer, String> FTYPE_SUB_DIR_DICT = new HashMap<Integer, String>() {{
        put(FILEINFO_FTYPE_IMAGE.getValue(), "image");
        put(FILEINFO_FTYPE_AUDIO.getValue(), "audio");
        put(FILEINFO_FTYPE_VIDEO.getValue(), "video");
        put(FILEINFO_FTYPE_FILE.getValue(), "files");
    }};

    String SURVEY_SUBMITED_COUNT_FORMAT = "__submited_count_%s_%s";

}


